use oop_simple::student::*;
use oop_simple::classes::*;
// 生命周期 标注
#[derive(Debug)]
struct StudentClassInfo<'a> {
    student_info:       Option<&'a StudentInfo>,
    classes_info:       Option<&'a ClassesInfo>
}

fn test_user_info() -> () {
    let classes_info1 = ClassesInfo { id: 1, classes_name: "三班".to_string(), grade_id: 1, school_id: 1 };
    let classes_info2 = ClassesInfo { id: 2, classes_name: "五班".to_string(), grade_id: 1, school_id: 1 };
    let classes_infos = vec![classes_info1, classes_info2];


    let mut user1 = StudentInfo { 
        classes_id: classes_infos[0].id,
        student_no: "18772963897".to_string(),
        people: PeopleInfo {
            name: "yangxuan".to_string(), 
            age: 18, 
            sex: Sex::MAN
        },
        profile_photo_url: None 
    };
    let user2 = StudentInfo::of(classes_infos[1].id, "18676391710".to_string(), "mina".to_string(), 18, Sex::WOMAN, None);
    let mut student_infos = vec![user1, user2];

    println!("{:?}", student_infos[0]);
    student_infos[0].people.sex(Sex::WOMAN);
    student_infos[0].people.age = 16;
    println!("{:?}", student_infos[0]);
    println!("{:?}", student_infos[1]);

    // 根据学号 寻找详细信息(学生及其所在学校信息)
    let find_student_class_by_student_no = |student_no: &str| -> StudentClassInfo {
        let student_info_o = student_infos.iter().find(|x| x.student_no == student_no);
        let classes_info_o = student_info_o.and_then(|x| classes_infos.iter().find(|y| x.classes_id == y.id));
        StudentClassInfo { student_info: student_info_o, classes_info: classes_info_o}
    };
    println!("{:?}", find_student_class_by_student_no("18772963897"));
    println!("----------------------");
    println!("{:?}", find_student_class_by_student_no("18676391710"));
}

fn main() {
    test_user_info();
}
